home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 76 / DVD Actual 1 Marzo 2003.iso / Trial / TurboCAD 7.1 Pro / Data.Cab / F25080_InsSymb.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-10  |  7.7 KB  |  364 lines

  1. // InsSymb.cpp : Implementation of CInsSymb
  2. #include "stdafx.h"
  3. #include "InsTool.h"
  4. #include "InsSymb.h"
  5. #include "TDialog.h"
  6.  
  7. /////////////////////////////////////////////////////////////////////////////
  8. //const IID IID_Tool = {0x6A48112C,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  9. //const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  10.  
  11.  
  12. // CInsSymb
  13.  
  14. STDMETHODIMP CInsSymb::InterfaceSupportsErrorInfo(REFIID riid)
  15. {
  16.     static const IID* arr[] = 
  17.     {
  18.         &IID_ITurboCADTool,
  19.     };
  20.     for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  21.     {
  22.         if (InlineIsEqualGUID(*arr[i],riid))
  23.             return S_OK;
  24.     }
  25.     return S_FALSE;
  26. }
  27.  
  28.  
  29. STDMETHODIMP CInsSymb::get_ClassID(BSTR* retval)
  30. {
  31.     HRESULT hRes = E_FAIL;
  32.     LPOLESTR olestr = NULL;
  33.  
  34.     try
  35.     {
  36.         *retval = NULL;
  37.  
  38.         hRes = ::StringFromCLSID(CLSID_InsSymb, &olestr);
  39.         CHECK_HRESULT(hRes)
  40.  
  41.         *retval = ::SysAllocString(olestr);
  42.  
  43.         hRes = S_OK;
  44.     }
  45.     catch (...)
  46.     {
  47.     
  48.         TRACE_EXCEPTION("CInsSymb::get_ClassID")
  49.         _clearfp();
  50.     }
  51.  
  52.     if (olestr != NULL)
  53.         CoTaskMemFree(olestr);
  54.  
  55.     return hRes;
  56. }
  57.  
  58. STDMETHODIMP CInsSymb::get_Description( BSTR* retval)
  59. {
  60.     HRESULT hRes = E_FAIL;
  61.     CString strResult;
  62.  
  63.     try
  64.     {
  65.         *retval = NULL;
  66.  
  67.         //CString strResult="Insert Symbol Tools"; //# Localizable string#
  68.         CString strResult;
  69.         strResult.LoadString(IDS_DESCRIPTION);
  70.         *retval =  strResult.AllocSysString();
  71.         hRes = S_OK;
  72.     }
  73.     catch (...)
  74.     {
  75.         TRACE_EXCEPTION("CInsSymb::get_Description")
  76.         _clearfp();
  77.     }
  78.     return hRes;
  79. }
  80.  
  81. /* ITurboCADTool methods: */
  82. STDMETHODIMP CInsSymb::GetToolInfo(VARIANT FAR* CommandNames,
  83.                                    VARIANT FAR* MenuCaptions,
  84.                                    VARIANT FAR* StatusPrompts,
  85.                                    VARIANT FAR* ToolTips,
  86.                                    VARIANT FAR* Enabled,
  87.                                    VARIANT FAR* WantsUpdates,
  88.                                    long FAR* retval)
  89. {
  90.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  91.  
  92.  
  93.     HRESULT hRes = E_FAIL;
  94.     
  95.     SAFEARRAYBOUND bound = {NUM_TOOLS, 0};
  96.  
  97.     CString cstrText;
  98.     CString cstrTextTemp;
  99.  
  100.     BSTR bstrCommandName = NULL;
  101.     BSTR bstrMenuCaption = NULL;
  102.     BSTR bstrStatusPrompt = NULL;
  103.     BSTR bstrToolTip = NULL;
  104.  
  105.     BOOL bEnabled = TRUE;
  106.     BOOL bWantsUpdates = TRUE;
  107.  
  108.     
  109.     long lIndicies = 0;
  110.     try
  111.     {
  112.         
  113.         hRes = SafeArrayRedim(CommandNames->parray, &bound);
  114.         CHECK_HRESULT(hRes)
  115.  
  116.         hRes = SafeArrayRedim(MenuCaptions->parray, &bound);
  117.         CHECK_HRESULT(hRes)
  118.  
  119.         hRes = SafeArrayRedim(StatusPrompts->parray, &bound);
  120.         CHECK_HRESULT(hRes)
  121.  
  122.         hRes = SafeArrayRedim(ToolTips->parray, &bound);
  123.         CHECK_HRESULT(hRes)
  124.  
  125.         hRes = SafeArrayRedim(Enabled->parray, &bound);
  126.         CHECK_HRESULT(hRes)
  127.  
  128.         hRes = SafeArrayRedim(WantsUpdates->parray, &bound);
  129.         CHECK_HRESULT(hRes)
  130.  
  131.         //CString cstrText="SDK|Insert_Symbol"; //# Localizable string#
  132.         cstrText.LoadString (IDS_MAINMENU);
  133.         cstrText.Insert(cstrText.GetLength (), '|');
  134.         cstrTextTemp.LoadString (IDS_SUBMENU);
  135.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  136.         cstrText.Insert(cstrText.GetLength (), '|');
  137.         cstrTextTemp.LoadString (IDS_MENUCAPTION);
  138.         cstrText.Insert(cstrText.GetLength (), cstrTextTemp);
  139.         cstrTextTemp.Empty ();
  140.  
  141.         bstrCommandName = cstrText.AllocSysString();
  142.         hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName);
  143.         CHECK_HRESULT(hRes)
  144.  
  145.         cstrText.Empty ();
  146.         cstrText.LoadString (IDS_MENUCAPTION); 
  147.         bstrMenuCaption = cstrText.AllocSysString();
  148.         hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption);
  149.         CHECK_HRESULT(hRes)
  150.  
  151.         cstrText.Empty ();
  152.          cstrText.LoadString (IDS_PROMT);
  153.         bstrStatusPrompt = cstrText.AllocSysString();
  154.         hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt);
  155.         CHECK_HRESULT(hRes)
  156.  
  157.         //cstrText="SDKInsertSymbol"; //# Localizable string#
  158.         cstrText.LoadString (IDS_TOOLTIPS);; 
  159.         bstrToolTip = cstrText.AllocSysString();
  160.         hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip);
  161.         CHECK_HRESULT(hRes)
  162.  
  163.         hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled);
  164.         CHECK_HRESULT(hRes)
  165.  
  166.         hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates);
  167.         CHECK_HRESULT(hRes)
  168.  
  169.         *retval = NUM_TOOLS;
  170.     }
  171.     catch (...)
  172.     {
  173.         if (SUCCEEDED(hRes))
  174.             hRes = E_FAIL;
  175.         TRACE_EXCEPTION("CInsSymb::GetToolInfo")
  176.         _clearfp();
  177.     }
  178.     return hRes;
  179. }
  180.  
  181. STDMETHODIMP CInsSymb::CopyBitmap( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL FAR* retval)
  182. {
  183.     HRESULT hRes = E_FAIL;
  184.     try
  185.     {
  186.         CHECK_HRESULT(hRes)
  187.         hRes = S_OK;
  188.     }
  189.     catch (...)
  190.     {
  191.         TRACE_EXCEPTION("CInsSymb::CopyBitmap")
  192.         _clearfp();
  193.     }
  194.     return hRes;
  195. }
  196.  
  197. STDMETHODIMP CInsSymb::GetPicture( VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch** retval)
  198. {
  199.     HRESULT hRes = E_FAIL;
  200.     try
  201.     {
  202.         CHECK_HRESULT(hRes)
  203.         hRes = S_OK;
  204.     }
  205.     catch (...)
  206.     {
  207.         TRACE_EXCEPTION("CAALBTool::GetPicture")
  208.         _clearfp();
  209.     }
  210.     return hRes;
  211. }
  212.  
  213. STDMETHODIMP CInsSymb::Run( IDispatch* ThisTool, VARIANT_BOOL FAR* retval)
  214. {
  215.     CWnd *pMainWnd = AfxGetMainWnd();
  216.  
  217.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  218.  
  219.     CInsToolApp *pApp = (CInsToolApp *)AfxGetApp();
  220.  
  221.     HRESULT hRes = E_FAIL;
  222.  
  223.     Tool *pThisTool = NULL;
  224.     IApplication *pIApp = NULL;
  225.  
  226.     IGraphic *pIGr = NULL;
  227.     Graphics *pGrs = NULL;
  228.  
  229.     IDrawing *pIDwg = NULL;
  230.  
  231.     Views *pVis = NULL;
  232.     View  *pVi = NULL;
  233.  
  234.     PickResult *pPickRes=NULL;
  235.     PickEntry *pPickEnt=NULL;
  236.  
  237.     RegenMethods *pRegMets=NULL;
  238.     RegenMethod *pIRegMet=NULL;
  239.  
  240.     COleVariant varAperture(0.2);
  241.     COleVariant varItem;
  242.     long lItem = 0;
  243.     long lIndex = 0;
  244.  
  245.     COleVariant varOptional(varMissing);
  246.     COleVariant varType((const long)imsiPolyline);
  247.     
  248.     VARIANT_BOOL    varCopy = FALSE;
  249.     VARIANT_BOOL    varRetval = FALSE;
  250.  
  251.     long lID = 0;
  252.  
  253.     BSTR bstrType = NULL;
  254.     CString    strType;
  255.  
  256.     BSTR bstrDescription=NULL;
  257.     CString strDescription;
  258.  
  259.     BSTR bstrName=NULL;
  260.     CString strName;
  261.  
  262.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  263.  
  264.     try
  265.     {
  266.  
  267.         hRes = ThisTool->QueryInterface(IID_Tool, (void **)&pThisTool);
  268.         CHECK_HRESULT(hRes)
  269.  
  270.         hRes = pThisTool->get_Application(&pIApp);
  271.         CHECK_HRESULT(hRes)
  272. /*
  273.         hRes = pIApp->get_ActiveDrawing(&pIDwg);
  274.         CHECK_HRESULT(hRes)
  275.  
  276.         hRes = pIDwg->get_Graphics(&pGrs);
  277.         CHECK_HRESULT(hRes)
  278.  
  279.         hRes = pIDwg->get_Views(&pVis);
  280.         CHECK_HRESULT(hRes)
  281.  
  282.         varItem = 0L;        
  283.         hRes = pVis->get_Item(&varItem,&pVi);
  284.         CHECK_HRESULT(hRes)
  285.  
  286.          hRes = pIApp->get_RegenMethods(&pRegMets);
  287.         CHECK_HRESULT(hRes)
  288. */
  289.  
  290.         CTDialog *pdlg = new CTDialog(this, pMainWnd, pThisTool);
  291.         pdlg->Create(CTDialog::IDD, NULL /*pMainWnd*/);
  292.  
  293.         VARIANT_BOOL    varRetval1 = false;
  294.         
  295.         hRes = UpdateToolStatus(ThisTool, &varRetval1, &varRetval1, &varRetval1);    
  296.         CHECK_HRESULT(hRes)
  297.  
  298.         pThisTool->Release();    
  299.         pThisTool = NULL;
  300.  
  301.  
  302. //        hRes = pVi->Refresh();
  303.         hRes = S_OK;
  304.     }
  305.     catch (...)
  306.     {
  307.         TRACE_EXCEPTION("CInsSymb::Run")
  308.         _clearfp();
  309.     }
  310.  
  311.  
  312. //    RELEASE(pIGr)
  313. //    RELEASE(pGrs)
  314. //    RELEASE(pIDwg)
  315. //    RELEASE(pVis)
  316. //    RELEASE(pVi)
  317.  
  318.     RELEASE(pThisTool)
  319.     RELEASE(pIApp)
  320.     ::SetCursor(hOC);
  321.  
  322.     return hRes;
  323. }
  324.  
  325. STDMETHODIMP CInsSymb::UpdateToolStatus(IDispatch* ThisTool, VARIANT_BOOL FAR* Enabled, VARIANT_BOOL FAR* Checked, VARIANT_BOOL FAR* retval)
  326. {
  327.     HRESULT hRes = E_FAIL;
  328.  
  329.     try
  330.     {
  331.         if(m_bRunned == TRUE) 
  332.         {
  333.             (*Enabled) = false;
  334.         }
  335.         *retval = TRUE;
  336.         hRes = S_OK;
  337.  
  338.     }
  339.     catch (...)
  340.     {
  341.         TRACE_EXCEPTION("CInsSymb::UpdateToolStatus")
  342.         _clearfp();
  343.     }
  344.  
  345.     return hRes;
  346. }
  347.  
  348. STDMETHODIMP CInsSymb::Initialize( IDispatch * ThisTool, VARIANT_BOOL FAR* retval)
  349. {
  350.     HRESULT hRes = E_FAIL;
  351.     try
  352.     {
  353.         m_pTCState = AfxGetModuleState();
  354.         *retval = TRUE;
  355.         hRes = S_OK;
  356.     }
  357.     catch (...)
  358.     {
  359.         TRACE_EXCEPTION("CInsSymb::Initialize")
  360.         _clearfp();
  361.     }
  362.     return hRes;
  363. }
  364.